package com.ubao.network.resp;

import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;

import com.ubao.network.RequestInterface;
import com.ubao.network.ResponseInterface;
import com.ubao.network.req.SpecialRequest;
import com.ubao.util.log.Logger;

public class SpecialResponse implements ResponseInterface {
	public String content;

	public short msg_id = -1;

	public void setData(HttpURLConnection conn, InputStream inputStream,
			RequestInterface requestInterface, boolean isCmwap)
			throws Exception {
		// TODO Auto-generated method stub
		SpecialRequest request = (SpecialRequest) requestInterface;
		StringBuffer buffer = new StringBuffer();

		InputStreamReader inputStreamReader;
		Logger.d(isCmwap ? request.encoding_cm : request.encoding);
		if (request.needEncoding)
			inputStreamReader = new InputStreamReader(inputStream,
					isCmwap ? request.encoding_cm : request.encoding);
		else
			inputStreamReader = new InputStreamReader(inputStream);

		int oneChar;
		while ((oneChar = inputStreamReader.read()) > -1) {
			// if (oneChar == '\n' && request.isNewLine)
			// buffer.append('\n');

			buffer.append((char) oneChar);
		}

		content = buffer.toString();
		Logger.d("content:" + content);
		msg_id = request.msg_id;
	}
}
